package com.dd.admin.business.stats;

import com.dd.admin.business.member.service.MemberService;
import com.dd.admin.business.memberCard.entity.MemberCard;
import com.dd.admin.business.memberCard.service.MemberCardService;
import com.dd.admin.business.product.entity.Product;
import com.dd.admin.business.product.service.ProductService;
import com.dd.admin.business.sell.service.SellService;
import com.dd.admin.business.sellDetail.domain.SellDetailVo;
import com.dd.admin.business.sellDetail.entity.SellDetail;
import com.dd.admin.business.sellDetail.service.SellDetailService;
import com.dd.admin.business.stats.domain.DashboardInfo;
import com.dd.admin.common.model.result.ResultBean;
import com.dd.admin.common.security.SecurityUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "统计相关")
@RestController
public class StatsController {

    @Autowired
    SellDetailService sellDetailService;
    @Autowired
    ProductService productService;
    @Autowired
    MemberService memberService;
    @Autowired
    MemberCardService memberCardService;
    @Autowired
    SellService sellService;

    @ApiOperationSupport(order = 1)
    @GetMapping("/admin/stats/getDashboardInfo")
    public ResultBean<DashboardInfo> getDashboardInfo() {
        DashboardInfo dashboardInfo = new DashboardInfo();
        String deptId = SecurityUtil.getLoginUser().getDeptId();
        Integer memberCount = memberService.selectMemberCount(deptId);
        dashboardInfo.setMemberCount(String.valueOf(memberCount));
        Integer memberCardCount = memberCardService.selectMemberCardCount(deptId);
        dashboardInfo.setMemberCardCount(String.valueOf(memberCardCount));
        Integer productCount = productService.selectProductCount(deptId);
        dashboardInfo.setProductCount(String.valueOf(productCount));
        Integer sellCount = sellService.selectSellCount(deptId);
        dashboardInfo.setSellCount(String.valueOf(sellCount));
        List<SellDetailVo> productProportion = sellDetailService.productProportion(SecurityUtil.getLoginUser().getDeptId(), 5);
        dashboardInfo.setProductSellProportion(productProportion);
        List<Product> productStockRank = productService.getProductStockRankByShopId(SecurityUtil.getLoginUser().getDeptId(), 5);
        dashboardInfo.setProductStockRank(productStockRank);
        return ResultBean.success(dashboardInfo);
    }
}
